<?php
namespace Admin\Controller;
use Think\Controller;

	class PhotosController extends CommonController{
		
		
		public function getlist(){
			$artid = $_GET['id'];
			
			$art_m = M('Article');
			//获取3列以上时，见开发手册
			$art = $art_m->where('id='.$artid)->getField('id,title,flag');
			$this->assign('art',$art[$artid]);
			
			$this->assign('flagname',$this->flag[$art[$artid]['flag']]);
			$this->assign('flagurl','/flag/'.$art[$artid]['flag']);
			
			$photo = M('Photos');
			$photolist = $photo->where('photoable_id='.$artid)->order('created_at desc')->select();
			$this->assign('data',$photolist);
			$this->display('Photos/list');
	    }
		
		
		public function uploadimg(){
			
			$upload = new \Think\Upload();   
			$upload->maxSize   =     3145728 ;
			$upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');
			$upload->savePath  =      '/images/'; 
			// 上传文件   js使用formdata 方式上传,formdata还真是 好用 啊 
			$info   =   $upload->uploadOne($_FILES['upload_file']);
			if(!$info) {// 上传错误提示错误信息
			    $this->show('error');
			}else{// 上传成功 获取上传文件信息
			    $path = '/Uploads'.$info['savepath'].$info['savename'];
			    $m = D('Photos');
			    $_POST['path'] = $path;
			   
				if(!$m->create()){
					$this->show('error2');
				}
				$id = $m->add();
				if($id>0){
					$result['id'] = $id;
					if($_POST['is_editer']){
						$result['path'] = __ROOT__.$path;
					}else {
						$result['path'] =$path;
					}
					
					$this->ajaxReturn($result);
					//$this->show($id);
				}else{
					$this->show('0');
				}
			}
			
			
		}
	}
?>
